package com.bookRecommend.mapper;


import com.bookRecommend.model.Book;
import com.bookRecommend.provider.BookProvider;
import org.apache.ibatis.annotations.*;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
* @author Administrator
* @description 针对表【book(图书表)】的数据库操作Mapper
* @createDate 2022-07-20 21:58:03
* @Entity .Books
*/
public interface IBookMapper {

    @Select("select * from book")
    List<Book> selectAllBooks();

    @SelectProvider(BookProvider.class)
    List<Book> selectByBook(Book book);

    @InsertProvider(BookProvider.class)
    int insertBook(Book book);

    @UpdateProvider(BookProvider.class)
    int updateBook(Book book);

    @DeleteProvider(BookProvider.class)
    int deleteBook(Book book);

    @Select("select book.*,typename  from book, type where(type.id = book.typeid)")
    List<Book> selectPage();

    @Select("select book.*, t.a as scoreavg from book join (select bookid,avg(score) " +
            "as a from score group by bookid ) t on t.bookid = book.id order by a desc limit 0,4")
    List<Book> selectHot();

    @Select("select book.*, t.a as scorecount from book join (select bookid,count(score) " +
            "as a from score group by bookid ) t on t.bookid = book.id order by a desc limit 0,4")
    List<Book> selectHotScore();
}




